<?php

namespace Summer\Shop\Http\Controllers;

use Illuminate\Routing\Controller;
use RLuders\JWTAuth\Classes\JWTAuth;
use Input;
use Config;
use Db;
use Event;
use Exception;
use Summer\Hub\Http\Controllers\Traits\ApiReturn;
use Summer\Shop\Models\OrderModel;

class UserController extends Controller
{
    use ApiReturn;

    /**
     * 商城相关用户信息
     * @param JWTAuth $auth
     * @return \Illuminate\Http\JsonResponse
     */
    public function userData(JWTAuth $auth)
    {
        if (!$user = $auth->user()) {
            return $this->apiError('登录失效,请重新登录');
        }
        $order_num=[];
        $order_status_slug_config=Config::get('summer.shop::order_status_slug');
        foreach ($order_status_slug_config as $osscv){
            if($osscv['is_show']==1){
                $order_num[$osscv['slug']]=OrderModel::where('user_id',$user->id)->where('status_slug',$osscv['slug'])->count();
            }
        }
        $return['order_num']=$order_num;
        return $this->apiSuccess('操作成功',$return);
    }
}
